//
//  ViewController.m
//  TextView
//
//  Created by IT-APP on 26/1/16.
//  Copyright © 2016年 IT-APP. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) UIToolbar *toolBar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _textView.backgroundColor = [UIColor grayColor];
    
    _toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
    _toolBar.barStyle = UIBarStyleDefault;
  
    UIBarButtonItem *item1 =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    
    UIBarButtonItem *item2 =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    UIBarButtonItem *item3 =[[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(resignKeyboard)];
    _toolBar.items = @[item1,item2,item3];
    
    _textView.inputAccessoryView = _toolBar;
    
    _textView.delegate = self;
    
}

-(void)textViewDidChange:(UITextView *)textView{
    
    CGSize size = [textView.text boundingRectWithSize:CGSizeMake(240, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:textView.font} context:nil].size;
    
    CGRect frame = _textView.frame;
    frame.size.height = size.height+7;
    
    ////ooo
    _textView.frame = frame;
    
}

-(void)resignKeyboard{
    [_textView resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
